/*   1:    */ package gov.chinatax.skskj.tools;
/*   2:    */ 
/*   3:    */ import gov.sat.tax.fwsk.common.TransFormatServlet;
/*   4:    */ import java.io.File;
/*   5:    */ import java.io.FileInputStream;
/*   6:    */ import java.io.FileOutputStream;
/*   7:    */ import java.io.InputStream;
/*   8:    */ import java.io.PrintStream;
/*   9:    */ import java.sql.ResultSet;
/*  10:    */ import java.sql.ResultSetMetaData;
/*  11:    */ import java.sql.SQLException;
/*  12:    */ import java.text.SimpleDateFormat;
/*  13:    */ import java.util.Date;
/*  14:    */ import java.util.Iterator;
/*  15:    */ import java.util.Map;
/*  16:    */ import java.util.Map.Entry;
/*  17:    */ import java.util.Set;
/*  18:    */ 
/*  19:    */ public class CreateXmlBean
/*  20:    */ {
/*  21:    */   public static String parseString(String param)
/*  22:    */   {
/*  23: 43 */     String rMw = "";
/*  24: 44 */     for (int i = 0; i < param.length(); i++)
/*  25:    */     {
/*  26: 46 */       char cPos = param.charAt(i);
/*  27: 47 */       if (cPos == '<') {
/*  28: 47 */         rMw = rMw + "&lt;";
/*  29: 48 */       } else if (cPos == '>') {
/*  30: 48 */         rMw = rMw + "&gt;";
/*  31: 49 */       } else if (String.valueOf(cPos).equals("'")) {
/*  32: 49 */         rMw = rMw;
/*  33:    */       } else {
/*  34: 53 */         rMw = rMw + String.valueOf(cPos);
/*  35:    */       }
/*  36:    */     }
/*  37: 56 */     return rMw;
/*  38:    */   }
/*  39:    */   
/*  40:    */   public static String genXMLResult(ResultSet rs, String nsrsbh)
/*  41:    */     throws SQLException
/*  42:    */   {
/*  43: 65 */     StringBuffer buffer = new StringBuffer(4096);
/*  44: 68 */     if (rs == null)
/*  45:    */     {
/*  46: 70 */       buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
/*  47: 71 */       buffer.append("<body>\n");
/*  48: 72 */       buffer.append("\t<head>\n");
/*  49: 73 */       buffer.append("\t\t<nsr>").append(nsrsbh).append("</nsr>\n");
/*  50: 74 */       buffer.append("\t\t<rows>0</rows>\n");
/*  51: 75 */       buffer.append("\t\t<je_sum>0.00</je_sum>\n");
/*  52: 76 */       buffer.append("\t</head>\n");
/*  53: 77 */       buffer.append("</body>\n");
/*  54: 78 */       return buffer.toString();
/*  55:    */     }
/*  56: 82 */     buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
/*  57: 83 */     buffer.append("<body>\n");
/*  58:    */     
/*  59:    */ 
/*  60: 86 */     ResultSetMetaData rsmd = rs.getMetaData();
/*  61:    */     
/*  62: 88 */     int colCount = rsmd.getColumnCount();
/*  63: 89 */     buffer.append("\t<data>\n");
/*  64:    */     
/*  65: 91 */     int id = 0;
/*  66: 91 */     for (int in = 0; (in < 5000) && (rs.next()); in++)
/*  67:    */     {
/*  68: 96 */       buffer.append("\t<row id=\"").append(id).append("\">\n");
/*  69: 98 */       for (int i = 1; i <= colCount; i++)
/*  70:    */       {
/*  71:101 */         int type = rsmd.getColumnType(i);
/*  72:102 */         buffer.append("\t\t<" + rsmd.getColumnName(i) + ">");
/*  73:103 */         buffer.append(TransFormatServlet.unicodeToGB(getValue(rs, i, type)));
/*  74:104 */         buffer.append("</" + rsmd.getColumnName(i) + ">\n");
/*  75:    */       }
/*  76:106 */       buffer.append("\t</row>\n");id++;
/*  77:    */     }
/*  78:108 */     buffer.append("\t</data>\n");
/*  79:109 */     buffer.append("</body>");
/*  80:110 */     rs.close();
/*  81:    */     
/*  82:112 */     return buffer.toString();
/*  83:    */   }
/*  84:    */   
/*  85:    */   public static String genZzsXMLResult(ResultSet rs, String nsrsbh)
/*  86:    */     throws SQLException
/*  87:    */   {
/*  88:121 */     StringBuffer buffer = new StringBuffer(8192);
/*  89:124 */     if (rs == null)
/*  90:    */     {
/*  91:126 */       buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
/*  92:127 */       buffer.append("<body>\n");
/*  93:128 */       buffer.append("\t<head>\n");
/*  94:129 */       buffer.append("\t\t<nsr>").append(nsrsbh).append("</nsr>\n");
/*  95:130 */       buffer.append("\t\t<rows>0</rows>\n");
/*  96:131 */       buffer.append("\t\t<je_sum>0.00</je_sum>\n");
/*  97:132 */       buffer.append("\t\t<se_sum>0.00</se_sum>\n");
/*  98:133 */       buffer.append("\t</head>\n");
/*  99:134 */       buffer.append("</body>\n");
/* 100:135 */       return buffer.toString();
/* 101:    */     }
/* 102:139 */     buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
/* 103:140 */     buffer.append("<body>\n");
/* 104:    */     
/* 105:    */ 
/* 106:143 */     ResultSetMetaData rsmd = rs.getMetaData();
/* 107:    */     
/* 108:145 */     int colCount = rsmd.getColumnCount();
/* 109:    */     
/* 110:    */ 
/* 111:148 */     buffer.append("\t<data>\n");
/* 112:    */     
/* 113:150 */     int id = 0;
/* 114:150 */     for (int in = 0; (in < 5000) && (rs.next()); in++)
/* 115:    */     {
/* 116:155 */       buffer.append("\t<row id=\"").append(id).append("\">\n");
/* 117:157 */       for (int i = 1; i <= colCount; i++)
/* 118:    */       {
/* 119:160 */         int type = rsmd.getColumnType(i);
/* 120:161 */         buffer.append("\t\t<" + rsmd.getColumnName(i) + ">");
/* 121:162 */         buffer.append(TransFormatServlet.unicodeToGB(getValue(rs, i, type)));
/* 122:163 */         buffer.append("</" + rsmd.getColumnName(i) + ">\n");
/* 123:    */       }
/* 124:165 */       buffer.append("\t</row>\n");id++;
/* 125:    */     }
/* 126:167 */     buffer.append("\t</data>\n");
/* 127:168 */     buffer.append("</body>");
/* 128:169 */     rs.close();
/* 129:    */     
/* 130:171 */     return buffer.toString();
/* 131:    */   }
/* 132:    */   
/* 133:    */   public static String genXMLHeadResult(String nsrsbh, int hs, String je)
/* 134:    */     throws SQLException
/* 135:    */   {
/* 136:181 */     StringBuffer buffer = new StringBuffer(1024);
/* 137:    */     
/* 138:183 */     buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
/* 139:184 */     buffer.append("<body>\n");
/* 140:185 */     buffer.append("\t<nsr>").append(nsrsbh).append("</nsr>\n");
/* 141:186 */     buffer.append("\t<rows>").append(hs).append("</rows>\n");
/* 142:187 */     buffer.append("\t<je_sum>").append(je).append("</je_sum>\n");
/* 143:188 */     buffer.append("</body>\n");
/* 144:189 */     return buffer.toString();
/* 145:    */   }
/* 146:    */   
/* 147:    */   public static String genXMLHeadResult(String nsrsbh, int hs, String je, String se)
/* 148:    */     throws SQLException
/* 149:    */   {
/* 150:198 */     StringBuffer buffer = new StringBuffer(1024);
/* 151:    */     
/* 152:200 */     buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
/* 153:201 */     buffer.append("<body>\n");
/* 154:202 */     buffer.append("\t<nsr>").append(nsrsbh).append("</nsr>\n");
/* 155:203 */     buffer.append("\t<rows>").append(hs).append("</rows>\n");
/* 156:204 */     buffer.append("\t<je_sum>").append(je).append("</je_sum>\n");
/* 157:205 */     buffer.append("\t<se_sum>").append(se).append("</se_sum>\n");
/* 158:206 */     buffer.append("</body>\n");
/* 159:207 */     return buffer.toString();
/* 160:    */   }
/* 161:    */   
/* 162:    */   public static boolean genXMLZip(ResultSet rs, FileOutputStream xmlFile)
/* 163:    */     throws Exception
/* 164:    */   {
/* 165:214 */     StringBuffer buffer = null;
/* 166:215 */     byte[] buf = (byte[])null;int icount = 0;
/* 167:    */     try
/* 168:    */     {
/* 169:218 */       if (rs == null)
/* 170:    */       {
/* 171:220 */         buffer = new StringBuffer(1024);
/* 172:221 */         buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
/* 173:222 */         buffer.append("<root>\n");
/* 174:223 */         buffer.append("</root>\n");
/* 175:224 */         buf = new byte[buffer.toString().length()];
/* 176:225 */         xmlFile.write(buf, 0, buf.length);
/* 177:226 */         xmlFile.close();
/* 178:227 */         buf = (byte[])null;
/* 179:228 */         return true;
/* 180:    */       }
/* 181:230 */       buffer = new StringBuffer(4096);
/* 182:    */       
/* 183:    */ 
/* 184:233 */       buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
/* 185:234 */       buffer.append("<root>\n");
/* 186:    */       
/* 187:    */ 
/* 188:237 */       ResultSetMetaData rsmd = rs.getMetaData();
/* 189:    */       
/* 190:    */ 
/* 191:240 */       int colCount = rsmd.getColumnCount();
/* 192:245 */       for (int id = 0; rs.next(); id++)
/* 193:    */       {
/* 194:248 */         buffer.append("\t<row id=\"").append(id).append("\">\n");
/* 195:250 */         for (int i = 1; i <= colCount; i++)
/* 196:    */         {
/* 197:253 */           int type = rsmd.getColumnType(i);
/* 198:    */           
/* 199:255 */           buffer.append("\t\t<" + rsmd.getColumnName(i) + ">");
/* 200:256 */           buffer.append(TransFormatServlet.unicodeToGB(getValue(rs, i, type)));
/* 201:257 */           buffer.append("</" + rsmd.getColumnName(i) + ">\n");
/* 202:    */         }
/* 203:259 */         buffer.append("\t</row>\n");
/* 204:262 */         if (id % 1000 == 0) {
/* 205:263 */           System.out.println("[INFO] 当前处理文件位置：row id = " + id);
/* 206:    */         }
/* 207:265 */         if (id / 10000 > icount)
/* 208:    */         {
/* 209:267 */           icount++;
/* 210:268 */           buf = new byte[buffer.toString().length()];
/* 211:269 */           buf = buffer.toString().getBytes();
/* 212:270 */           xmlFile.write(buf, 0, buf.length);
/* 213:271 */           buffer.delete(0, buffer.toString().length());
/* 214:272 */           buf = (byte[])null;
/* 215:    */         }
/* 216:    */       }
/* 217:276 */       buffer.append("</root>");
/* 218:277 */       buf = new byte[buffer.toString().length()];
/* 219:278 */       buf = buffer.toString().getBytes();
/* 220:279 */       xmlFile.write(buf, 0, buf.length);
/* 221:280 */       xmlFile.close();
/* 222:281 */       buf = (byte[])null;
/* 223:    */       
/* 224:283 */       rs.close();
/* 225:    */       
/* 226:285 */       return true;
/* 227:    */     }
/* 228:    */     catch (Exception e)
/* 229:    */     {
/* 230:289 */       System.out.println("[ERROR] genXMLZip :" + e.toString());
/* 231:    */     }
/* 232:290 */     return false;
/* 233:    */   }
/* 234:    */   
/* 235:    */   public static boolean fileCopy(String inDir, String outDir)
/* 236:    */     throws Exception
/* 237:    */   {
/* 238:    */     try
/* 239:    */     {
/* 240:298 */       int bytesum = 0;
/* 241:299 */       int byteread = 0;
/* 242:    */       
/* 243:301 */       InputStream inStream = new FileInputStream(inDir);
/* 244:302 */       FileOutputStream fs = new FileOutputStream(outDir);
/* 245:303 */       byte[] buffer = new byte[8192];
/* 246:305 */       while ((byteread = inStream.read(buffer)) != -1)
/* 247:    */       {
/* 248:307 */         bytesum += byteread;
/* 249:    */         
/* 250:309 */         fs.write(buffer, 0, byteread);
/* 251:    */       }
/* 252:311 */       inStream.close();
/* 253:312 */       return true;
/* 254:    */     }
/* 255:    */     catch (Exception e)
/* 256:    */     {
/* 257:316 */       System.out.println("[ERROR] fileCopy error : " + e.toString());
/* 258:    */     }
/* 259:317 */     return false;
/* 260:    */   }
/* 261:    */   
/* 262:    */   public static int createDir(String inDirFile)
/* 263:    */     throws Exception
/* 264:    */   {
/* 265:324 */     String filePath = inDirFile;
/* 266:325 */     boolean dirflag = false;
/* 267:326 */     File myFilePath = new File(filePath);
/* 268:327 */     if (!myFilePath.exists())
/* 269:    */     {
/* 270:328 */       dirflag = myFilePath.mkdir();
/* 271:    */     }
/* 272:    */     else
/* 273:    */     {
/* 274:331 */       System.out.println("[INFO] 临时目录c:\\jktemp已经存在！");
/* 275:332 */       return 1;
/* 276:    */     }
/* 277:334 */     if (dirflag)
/* 278:    */     {
/* 279:336 */       System.out.println("[INFO] 临时目录c:\\jktemp创建成功！");
/* 280:337 */       return 0;
/* 281:    */     }
/* 282:341 */     System.out.println("[ERROR] 临时目录c:\\jktemp创建失败！");
/* 283:342 */     return 2;
/* 284:    */   }
/* 285:    */   
/* 286:    */   private static String getValue(ResultSet rs, int colNum, int type)
/* 287:    */     throws SQLException
/* 288:    */   {
					Object value;
/* 289:357 */     switch (type)
/* 290:    */     {
/* 291:    */     case -4: 
/* 292:    */     case -3: 
/* 293:    */     case -2: 
/* 294:    */     case 2001: 
/* 295:    */     case 2002: 
/* 296:    */     case 2003: 
/* 297:    */     case 2004: 
/* 298:    */     case 2005: 
/* 299:    */     case 2006: 
/* 300:368 */       return "no";
/* 301:    */     case 1: 
/* 302:    */     case 12: 
/* 303:372 */        value = rs.getObject(colNum);
/* 304:374 */       if ((rs.wasNull()) || (value == null)) {
/* 305:374 */         return "no";
/* 306:    */       }
/* 307:375 */       if (value.toString().trim().length() == 0) {
/* 308:375 */         return "no";
/* 309:    */       }
/* 310:376 */       if (value.toString().trim().equals("null")) {
/* 311:376 */         return "no";
/* 312:    */       }
/* 313:377 */       if ((type == 12) || (type == 1)) {
/* 314:378 */         return parseString(value.toString());
/* 315:    */       }
/* 316:    */     case 91: 
/* 317:382 */        value = rs.getTimestamp(colNum);
/* 318:383 */       if ((rs.wasNull()) || (value == null)) {
/* 319:383 */         return "no";
/* 320:    */       }
/* 321:384 */       if (type == 91) {
/* 322:386 */         return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(value);
/* 323:    */       }
/* 324:    */     case 4: 
/* 325:    */     case 6: 
/* 326:    */     case 8: 
/* 327:392 */        value = rs.getObject(colNum);
/* 328:393 */       if ((rs.wasNull()) || (value == null)) {
/* 329:393 */         return "0";
/* 330:    */       }
/* 331:395 */       return value.toString();
/* 332:    */     }
/* 333:399 */      value = rs.getObject(colNum);
/* 334:400 */     if ((rs.wasNull()) || (value == null)) {
/* 335:400 */       return "no";
/* 336:    */     }
/* 337:402 */     return value.toString();
/* 338:    */   }
/* 339:    */   
/* 340:    */   public static String genWpmxXMLResult(ResultSet rs, String rz_nsrsbh)
/* 341:    */     throws SQLException
/* 342:    */   {
/* 343:408 */     StringBuffer buffer = new StringBuffer(8192);
/* 344:409 */     buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
/* 345:410 */     buffer.append("<ROOT>\n");
/* 346:411 */     if (rs == null)
/* 347:    */     {
/* 348:413 */       buffer.append("</ROOT>");
/* 349:414 */       return buffer.toString();
/* 350:    */     }
/* 351:418 */     ResultSetMetaData rsmd = rs.getMetaData();
/* 352:    */     
/* 353:420 */     int colCount = rsmd.getColumnCount();
/* 354:422 */     for (int id = 0; rs.next(); id++)
/* 355:    */     {
/* 356:426 */       buffer.append("<WP>\n");
/* 357:427 */       for (int i = 1; i <= colCount; i++)
/* 358:    */       {
/* 359:430 */         int type = rsmd.getColumnType(i);
/* 360:431 */         buffer.append("\t<" + rsmd.getColumnName(i) + ">");
/* 361:432 */         buffer.append(TransFormatServlet.unicodeToGB(getValue(rs, i, type)));
/* 362:433 */         buffer.append("</" + rsmd.getColumnName(i) + ">\n");
/* 363:    */       }
/* 364:435 */       buffer.append("</WP>\n");
/* 365:    */     }
/* 366:437 */     buffer.append("</ROOT>");
/* 367:438 */     rs.close();
/* 368:    */     
/* 369:440 */     return buffer.toString();
/* 370:    */   }
/* 371:    */   
/* 372:    */   public static String genCmpResult(Map map, boolean isSuccess)
/* 373:    */     throws SQLException
/* 374:    */   {
/* 375:444 */     StringBuffer buffer = new StringBuffer();
/* 376:445 */     buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
/* 377:446 */     buffer.append("<ROOT>\n");
/* 378:    */     
/* 379:448 */     buffer.append("<success>\n");
/* 380:449 */     buffer.append(isSuccess);
/* 381:450 */     buffer.append("</success>\n");
/* 382:    */     
/* 383:452 */     Iterator it = map.entrySet().iterator();
/* 384:453 */     while (it.hasNext())
/* 385:    */     {
/* 386:454 */       Map.Entry entry = (Map.Entry)it.next();
/* 387:455 */       String key = (String)entry.getKey();
/* 388:456 */       buffer.append("<" + key + ">\n");
/* 389:457 */       String value = (String)entry.getValue();
/* 390:458 */       buffer.append(value);
/* 391:459 */       buffer.append("</" + key + ">\n");
/* 392:    */     }
/* 393:462 */     buffer.append("</ROOT>");
/* 394:    */     
/* 395:464 */     return buffer.toString();
/* 396:    */   }
/* 397:    */   
/* 398:    */   public static String genCmpResult1(Map map, boolean isSuccess)
/* 399:    */     throws SQLException
/* 400:    */   {
/* 401:481 */     StringBuffer buffer = new StringBuffer();
/* 402:482 */     buffer.append("<?xml version=\"1.0\" encoding=\"GBK\"?>");
/* 403:483 */     buffer.append("<ROOT>");
/* 404:    */     
/* 405:485 */     buffer.append("<success>");
/* 406:486 */     buffer.append(isSuccess);
/* 407:487 */     buffer.append("</success>");
/* 408:    */     
/* 409:489 */     Iterator it = map.entrySet().iterator();
/* 410:490 */     while (it.hasNext())
/* 411:    */     {
/* 412:491 */       Map.Entry entry = (Map.Entry)it.next();
/* 413:492 */       String key = (String)entry.getKey();
/* 414:493 */       buffer.append("<" + key + ">");
/* 415:494 */       String value = (String)entry.getValue();
/* 416:495 */       buffer.append(value);
/* 417:496 */       buffer.append("</" + key + ">");
/* 418:    */     }
/* 419:498 */     buffer.append("</ROOT>");
/* 420:499 */     return buffer.toString();
/* 421:    */   }
/* 422:    */ }


/* Location:           D:\htjs\document\wsrz\WsrzEjbInf\
 * Qualified Name:     gov.chinatax.skskj.tools.CreateXmlBean
 * JD-Core Version:    0.7.0.1
 */